package com.java1412.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.io.Serializable;

/**
 * 响应给页面的数据的工具类
 *
 * @author java1412
 * @since 2023-06-20 16:34:35
 */
public class ResponseUtil implements Serializable {

    private Integer code; // 状态码
    private String msg;// 提示消息
    private Object data;

    private ResponseUtil(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    private ResponseUtil(Integer code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    // 成功
    public static ResponseUtil ok(String msg) {
        return createR(200, msg);
    }

    // 成功带数据
    public static ResponseUtil ok(String msg, Object data) {
        ResponseUtil responseUtil = createR(200, msg);
        responseUtil.setData(data);
        return responseUtil;
    }

    // 失败
    public static ResponseUtil fail(String msg) {
        return createR(400, msg);
    }

    // 创建ResponseUtil包含两个个属性
    public static ResponseUtil createR(Integer code, String msg) {
        return new ResponseUtil(code, msg);
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
